<?php

class SPIcontroller__enotifier extends SPIcontroller__dummy
{
    protected function push( $priorety, $emailto, $vars, $template_name, $content_type = 'plain' )
    {
        list( $subject, $message ) = SPIv::I('enotifier')->render( $vars, $template_name );

        $headers = '';

        switch( $content_type )
        {
            case 'plain':
            {
                $headers.= "Content-type: text/plain; charset=WINDOWS-1251\r\n";
                break;
            }

            case 'html':
            {
                $message = preg_replace( '|(<a[^ ]* href=[\'"])/|iu',  '\1'. trim(SPIcfg::$hostnames['base'],'/') .'/', $message );
                $message = preg_replace( '|(<img[^ ]* src=[\'"])/|iu', '\1'. trim(SPIcfg::$hostnames['base'],'/') .'/', $message );

                $headers.= "Content-type: text/html; charset=WINDOWS-1251\r\n";
                break;
            }
        }

        $headers.= "From: Smak.ua messager <noreply@smak.ua>\r\n"
                 . "Reply-To: Smak.ua messager <noreply@smak.ua>\r\n"
                 ;

        $subject = iconv( 'UTF-8', 'WINDOWS-1251', $subject );
        $message = iconv( 'UTF-8', 'WINDOWS-1251', $message );

        return @ mail( $emailto, $subject, $message, $headers );
    }
}
